﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RedHouse.Data.Service;
using RedHouse.Data.Common;

namespace RedHouse.Data.Base
{
    public class ImageService : IImageService
    {
        #region Declaration
        NewRedHouseEntitiesDataContext _dataContext;
        #endregion

        public ImageService()
        {
            _dataContext = new NewRedHouseEntitiesDataContext();
        }

        #region IImageService Members

        public OperationResult SaveImage(Image image)
        {
            OperationResult result = new OperationResult()
            {
                Result = true,
                Message = "Save Successfully!"
            };

            try
            {
                _dataContext.Images.InsertOnSubmit(image);
                _dataContext.SubmitChanges();
                result.ReturnObject = image;
                return result;
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.Message = ex.Message;
                return result;
            }
        }

        public List<Image> GetAllImageByAssociatedId(Guid associatedId)
        {
            return _dataContext.Images.Where(i => i.AssociatedID == associatedId).ToList();
        }

        #endregion
    }
}
